<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8" />
    <title>grid信息管理</title>
    <link rel="stylesheet" href="/static/basic/plugins/easyui/themes/bootstrap/easyui.css" >
	<link rel="stylesheet" href="/static/basic/plugins/easyui/themes/icon.css" >
	<link rel="stylesheet" type="text/css" href="https://cdn.staticfile.org/font-awesome/5.12.1/css/all.min.css" >
	<script src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js"></script>
	<script src="/static/basic/plugins/easyui/jquery.easyui.min.js"></script>
	<script src="/static/init.js"></script>
	<script src="/static/searchEdit.js?v=1"></script>
	<script src="/static/basic/plugins/easyui/locale/easyui-lang-zh_CN.js"></script>
	<script src="https://cdn.staticfile.org/moment.js/2.24.0/moment.min.js"></script>
	
	<link rel="stylesheet" type="text/css" href="/static/m.css" >
</head>
<body>
<div class="easyui-layout" data-options="fit:true" >
	<div data-options="region:'center'" >
		<table id="gridList" ></table>
	</div>
</div>
<div id="searchbar" >
	<div class="maction">
	<a href="javascript:void(0)" id="initColumnButton" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'">初始化字段</a>
		<a href="javascript:void(0)" id="addButton" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'">新增</a>
			<a href="javascript:void(0)" id="editButton" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-edit'">编辑</a>
			<a href="javascript:void(0)" id="removeButton" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-remove'">删除</a>
			<a href="javascript:void(0)" id="saveButton" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-save'">保存</a>
			<a href="javascript:void(0)" id="btn1" class="easyui-linkbutton" data-options="plain:true">属性设置</a>
	</div>
	<form id="searchForm" >
		页面id:<input id="search-page_id" name="page_id" class="easyui-textbox" >
		<a id="searchButton" href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-search'" >查询</a>
	</form>
</div>
<script>
var options={
		page_id:38,
		grid_id:"gridList",
		pager_id:"pager",
		sqlname:"grid_sys_grid_column"
	};
	//document ready
	$(function(){
		grid1=new uniontrip.datagrid.searchEdit(options);
		
		$('#addButton').bind('click', addRow);//新增行绑定事件
		$('#editButton').bind('click',grid1.editRow);//编辑按钮绑定事件
		$('#removeButton').bind('click',grid1.remove);//删除行绑定事件
		
		$('#searchButton').bind('click',grid1.load);//查询操作绑定事件
		$('#saveButton').bind('click', grid1.accept);//保存datagrid绑定事件
		$('#cancelEditButton').bind('click',grid1.cancelEditing);//取消行编辑绑定事件
		$('#endEditingButton').bind('click', grid1.endEditing);//结束行编辑绑定事件
		$('#rejectButton').bind('click', grid1.rejectChanges);//撤销编辑绑定事件		
	    $('#showChangesButton').bind('click',grid1.showChanges);//信息变更提示
	    
	    $('#initColumnButton').bind('click', function(){
	    	EditDialog2.dialog('open');
	    });
	    //初始化搜索框
	    initsearch();
	    $('#btn1').bind('click',function(){
	    	var selectRows=grid1.grid.datagrid('getSelections');
			if(selectRows.length>0){
				EditDialog.dialog('open');
				
			}else{
				info("请选择一条数据！");
			}
	    });
	    
	    EditDialog2=$("<div/>").appendTo("body").dialog({
			title:"初始化",
			cls:"m-dialog",
			width:'400px',
			//height:windowHeight*0.8,
			height:'300px',
			//href:'/grid/form/insert/view?grid_id=215',
			href:'add.html',
			modal:true,
			closed:true,
			//maximized:true,
			onClose:function(){
				console.log('onClose');
				
			},
			onBeforeClose:function(){//
				console.log('onBeforeClose');
				$("#form1").form('clear');
				//$("#smartwizard").data("smartWizard").options.anchorSettings.enableAllAnchors=false;
				//$('#smartwizard').smartWizard('reset');
			},
			 buttons: [{
				text:'保存&关闭',
				iconCls:'fas fa-save mbutton',
				handler:function(){
					addSubmit(true);
				}
			},{
				text:'取消',
				iconCls:'fas fa-times mbutton',
				handler:function(){
					EditDialog2.dialog('close')
				}
			}],
			onBeforeOpen:function(){
				console.log('onBeforeOpen');
				if($(this).data("panel").isLoaded){
					
				}
			},
			onOpened:function(){
				console.log('onOpened');
				let parent_id=$("#form1 :input[name=parent_id]").first();
				parent_id.val(parentNode.id);
			},
			onOpen:function(){//在onLoad之前执行
				console.log('onOpen');
				//console.log($(this).panel('options'));
				if($(this).data("panel").isLoaded){
					$(this).panel('options').onOpened();
				}
			},
			onBeforeLoad:function(){
				console.log('onBeforeLoad');
			},
			onLoad:function(){//只加载一次
				console.log('onLoad');
				//document.getElementById("id").fireEvent("click");
				$(this).panel('options').onOpened();
				//$('#lng').iCheck();
			},
		});
	    EditDialog=$("<div/>").appendTo("body").dialog({
			title:"设置属性",
			cls:"m-dialog",
			/*width:'100%',
			height:dialogHeight,*/
			href:'property.html',
			modal:true,
			closed:true,
			maximized:true,
			onClose:function(){
				
			},
			onBeforeClose:function(){
				
			},
			 buttons: [{
				text:'保存',
				iconCls:'fas fa-save mbutton',
				handler:saveProperty
			},{
				text:'取消',
				iconCls:'fas fa-times mbutton',
				handler:function(){
					EditDialog.dialog('close')
				}
			}],
			onOpen:function(){
				
			},
			onLoad:function(){
				$("#propertyGrid").datagrid({
					url:"",
				    columns:[[
				        {field:'property_name',title:'属性名'},
				        {field:'value',title:'属性值'},
				        {field:'type',title:'属性值类型'},
				        {field:'description',title:'说明'},
				        {field:'default_value',title:'默认值'}
				    ]]
				});
			}
		});
	});

	function saveProperty(){
		
	}
	var addUrl="/access/post?action=16936165806440448";
	function addSubmit(isClose){
		if ($("#form1").form("enableValidation").form("validate")){
			var formObject=$("#form1").serializeObject();
			$.ajax({
				type: "post",
				contentType:"application/json",
				url: addUrl,
				data:JSON.stringify(formObject),
				dataType:"json",
				success: function(result){
					if(result.success){
						info("保存成功！");
						if(isClose){
							EditDialog2.dialog('close');
						}
					}else{
						$.messager.alert("提示", "保存失败！");
					}
				},
				error: function(){
					$.messager.alert("提示", "请求失败！");
				}
			});
		}
	}
	/**
	 * 新增一行
	 */
	function addRow(){
		var newRowData={id:guid(),creator_id:sessionuser.id,creator_name:sessionuser.nickname,create_time:moment().format('YYYY-MM-DD')};//初始化行数据
		grid1.grid.datagrid('append',newRowData);	
	}
	/**
	 * 初始化搜索条件
	 */
	function initsearch(){
		/*$('#search-product_class_id').combotree({
			icons: [{
				iconCls:'icon-clear',
				handler:function(){
					$('#search-product_class_id').combotree('clear');
				}
			}],
		    data:grid1.combotreeDatas.product_class_id
		});
		//初始化combobox例子
		$('#search-status').combobox({
			panelHeight:'auto',
			editable:false,
			valueField:'code_value',
			textField:'code_name',
			icons: [{
				iconCls:'icon-clear',
				handler:function(){
					$('#search-status').combobox('clear');
				}
			}],
		    data:grid1.comboboxDatas.status
		});*/
	}
</script>
</body>
</html>